package com.xsm.activitygroup;

import java.util.ArrayList;

import cn.bidaround.youtui_template.YouTuiViewType;
import cn.bidaround.youtui_template.YtTemplate;
import cn.bidaround.ytcore.data.ShareData;

import com.umeng.analytics.MobclickAgent;
import com.xsm.activitygroup.R;
import com.xsm.adapter.MyAdapter;
import com.xsm.internet.ConnectUrl;
import com.xsm.view.Mydialog;

import android.R.integer;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class activity4 extends Activity{
ListView mylist;
Activity context;
MyAdapter adapter;
Button button;
String user;
private long exitTime = 0;
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity4);
	context=this;
	YtTemplate.init(this);/*初始化友推*/
	initView();
}
	protected void onResume() {
	mylist.setAdapter(adapter);
	MobclickAgent.onResume(this);
	super.onResume();
	}

	protected void onPause() {
	MobclickAgent.onResume(this);
		super.onPause();
	}
		protected void onDestroy() {
		YtTemplate.release(this);
			super.onDestroy();
		}
public void Login(View view){
	startActivity(new Intent(context,Login.class));
	finish();
}
private void initView(){
	button=(Button)findViewById(R.id.login);
	SharedPreferences sharedPreferences=getSharedPreferences("XSM", 0);
	user=sharedPreferences.getString("User", "");
	if(!user.equals(""))
	button.setVisibility(View.GONE);
	int icons[]=new int[]{R.drawable.message,R.drawable.trade,R.drawable.chongzhi,R.drawable.fankui,R.drawable.about,R.drawable.share};
	ArrayList<String> textArrayList=new ArrayList<String>();
	textArrayList.add("个人资料");
	textArrayList.add("交易详情");
	textArrayList.add("签到领金豆");
	textArrayList.add("反馈");
	textArrayList.add("关于");
	textArrayList.add("分享好友");

	
 	mylist=(ListView)findViewById(R.id.mylist);
	 adapter=new MyAdapter(context, icons, textArrayList);
	mylist.setAdapter(adapter);
	mylist.setOnItemClickListener(new OnItemClickListener() {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			
		if(arg2==4){
			startActivity(new Intent(context,About.class));
		}else if(arg2==5){
		    YtTemplate blackTemp = new YtTemplate(context, YouTuiViewType.WHITE_GRID,false);  //白色网格样式不需要积分活动
			ShareData shareData = new ShareData();
			shareData.isAppShare = true;//设置为true则分享的信息从友推后台填写的应用信息中读取，可动态更新，后面的值不用设置。
			shareData.setDescription("二手书籍交易平台");
			shareData.setTitle("书集为书籍交易平台，通过软件可以找到要买的二手书本。用户可以通过平台发布商品，通过平台实现书籍的循环利用。");
			shareData.setText("书集为书籍交易平台，通过软件可以找到要买的二手书本。用户可以通过平台发布商品，通过平台实现书籍的循环利用。");
			shareData.setTarget_url("http://youtui.mobi");
			shareData.setImageUrl("http://youtui.mobi/media/image/youtui.png");
			blackTemp.setShareData(shareData);//设置默认的分享数据;shareData 设置参看4.6
			blackTemp.show();
			
		}
			else {
			if(user.equals(""))	{
		final Mydialog mydialog=new Mydialog(context, "请先登陆");
		mydialog.setEnsureText("登陆");
		mydialog.settitle("提示");
		mydialog.setEnsurelistener(new OnClickListener() {
			public void onClick(View v) {
			startActivity(new Intent(context,Login.class));	
			mydialog.dissmissDialog();
			finish();
			}
		});
		mydialog.showDialog();
			}
						else {
							switch (arg2) {
							case 0:
							startActivity(new Intent(activity4.this,Usermessage.class));	
							break;
							case 1:
							startActivity(new Intent(activity4.this,Trade.class));
							break;				
							case 2:
							startActivity(new Intent(activity4.this,Qiandao.class));		
							break;
							case 3:
							startActivity(new Intent(activity4.this,FeedBack.class));	
							break;	
							default:
								break;
							}	
						}	
		}
		}
	});
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){   
        if((System.currentTimeMillis()-exitTime) > 2000){  
            Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_LONG).show();                                
            exitTime = System.currentTimeMillis();   
        } else {
         int pid=android.os.Process.myPid();
         android.os.Process.killProcess(pid);
        }
        return true;   
    }
    return super.onKeyDown(keyCode, event);
}
}
